import pygame
import sys

# Initialize pygame
pygame.init()

# Create the drawing screen
size = width, height = 640, 480
screen = pygame.display.set_mode(size)
speed = [1,1]
black = 0,0,0

ball = pygame.image.load("ball.gif")
ballrect = ball.get_rect()

while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: 
            sys.exit()
    ballrect = ballrect.move(speed)
    if ballrect.left < 0 or ballrect.right > width/2:
        speed[0] = -speed[0]
    if ballrect.top < 0 or ballrect.bottom > height/2:
        speed[1] = -speed[1]
    screen.fill(black)
    screen.blit(ball,ballrect)
    pygame.display.flip()
